/**
 * 菜单配置
 * 遵循苹果设计指南的导航结构
 */

// 菜单数据配置
export const menuData = [
  {
    path: '/dashboard',
    name: 'dashboard',
    label: '数据总览',
    icon: 'DataAnalysis',
    meta: {
      title: '数据总览',
      icon: 'DataAnalysis',
      keepAlive: true
    }
  },
  {
    path: '/customer',
    name: 'customer',
    label: '客户管理',
    icon: 'User',
    meta: {
      title: '客户管理',
      icon: 'User'
    },
    children: [
      {
        path: '/customer/list',
        name: 'customer-list',
        label: '客户列表',
        icon: 'Notebook',
        meta: {
          title: '客户列表',
          icon: 'Notebook',
          keepAlive: true
        }
      },
      {
        path: '/customer/detail',
        name: 'customer-detail',
        label: '客户详情',
        icon: 'View',
        meta: {
          title: '客户详情',
          icon: 'View',
          hidden: true // 隐藏在菜单中
        }
      },
      {
        path: '/customer/form',
        name: 'customer-form',
        label: '客户信息',
        icon: 'Edit',
        meta: {
          title: '客户信息',
          icon: 'Edit'
        }
      },
      {
        path: '/customer/tags',
        name: 'customer-tags',
        label: '客户标签',
        icon: 'CollectionTag',
        meta: {
          title: '客户标签',
          icon: 'CollectionTag'
        }
      }
    ]
  },
  {
    path: '/customer-analysis',
    name: 'customer-analysis',
    label: '客户分析',
    icon: 'PieChart',
    meta: {
      title: '客户分析',
      icon: 'PieChart'
    },
    children: [
      {
        path: '/customer-analysis/overview',
        name: 'customer-analysis-overview',
        label: '分析总览',
        icon: 'DataBoard',
        meta: {
          title: '分析总览',
          icon: 'DataBoard',
          keepAlive: true
        }
      },
      {
        path: '/customer-analysis/profile',
        name: 'customer-analysis-profile',
        label: '档案详情',
        icon: 'Document',
        meta: {
          title: '档案详情',
          icon: 'Document'
        }
      },
      {
        path: '/customer-analysis/segmentation',
        name: 'customer-analysis-segmentation',
        label: '客户分群',
        icon: 'DataLine',
        meta: {
          title: '客户分群',
          icon: 'DataLine'
        }
      },
      {
        path: '/customer-analysis/lifecycle',
        name: 'customer-analysis-lifecycle',
        label: '生命周期',
        icon: 'Refresh',
        meta: {
          title: '生命周期',
          icon: 'Refresh'
        }
      },
      {
        path: '/customer-analysis/behavior',
        name: 'customer-analysis-behavior',
        label: '行为预测',
        icon: 'TrendCharts',
        meta: {
          title: '行为预测',
          icon: 'TrendCharts'
        }
      },
      {
        path: '/customer-analysis/recommendation',
        name: 'customer-analysis-recommendation',
        label: '推荐配置',
        icon: 'Setting',
        meta: {
          title: '推荐配置',
          icon: 'Setting'
        }
      },
      {
        path: '/customer-analysis/insights',
        name: 'customer-analysis-insights',
        label: '洞察预警',
        icon: 'Warning',
        meta: {
          title: '洞察预警',
          icon: 'Warning'
        }
      }
    ]
  },
  {
    path: '/sales',
    name: 'sales',
    label: '销售管理',
    icon: 'Money',
    meta: {
      title: '销售管理',
      icon: 'Money'
    },
    children: [
      {
        path: '/sales/opportunities',
        name: 'sales-opportunities',
        label: '销售机会',
        icon: 'Opportunity',
        meta: {
          title: '销售机会',
          icon: 'Opportunity',
          keepAlive: true
        }
      },
      {
        path: '/sales/detail',
        name: 'sales-detail',
        label: '机会详情',
        icon: 'View',
        meta: {
          title: '机会详情',
          icon: 'View',
          hidden: true
        }
      },
      {
        path: '/sales/form',
        name: 'sales-form',
        label: '销售表单',
        icon: 'Edit',
        meta: {
          title: '销售表单',
          icon: 'Edit'
        }
      },
      {
        path: '/sales/follow-up',
        name: 'sales-follow-up',
        label: '跟进记录',
        icon: 'ChatLineSquare',
        meta: {
          title: '跟进记录',
          icon: 'ChatLineSquare'
        }
      },
      {
        path: '/sales/funnel',
        name: 'sales-funnel',
        label: '销售漏斗',
        icon: 'TrendCharts',
        meta: {
          title: '销售漏斗',
          icon: 'TrendCharts'
        }
      },
      {
        path: '/sales/contract',
        name: 'sales-contract',
        label: '合同支付',
        icon: 'Tickets',
        meta: {
          title: '合同支付',
          icon: 'Tickets'
        }
      },
      {
        path: '/sales/execution',
        name: 'sales-execution',
        label: '出团执行',
        icon: 'Guide',
        meta: {
          title: '出团执行',
          icon: 'Guide'
        }
      },
      {
        path: '/sales/aftercare',
        name: 'sales-aftercare',
        label: '售后服务',
        icon: 'CustomerService',
        meta: {
          title: '售后服务',
          icon: 'CustomerService'
        }
      }
    ]
  },
  {
    path: '/product',
    name: 'product',
    label: '线路产品',
    icon: 'Location',
    meta: {
      title: '线路产品',
      icon: 'Location'
    },
    children: [
      {
        path: '/product/list',
        name: 'product-list',
        label: '产品列表',
        icon: 'Goods',
        meta: {
          title: '产品列表',
          icon: 'Goods',
          keepAlive: true
        }
      },
      {
        path: '/product/create',
        name: 'product-create',
        label: '产品创建',
        icon: 'CirclePlus',
        meta: {
          title: '产品创建',
          icon: 'CirclePlus'
        }
      },
      {
        path: '/product/edit',
        name: 'product-edit',
        label: '产品编辑',
        icon: 'Edit',
        meta: {
          title: '产品编辑',
          icon: 'Edit',
          hidden: true
        }
      },
      {
        path: '/product/itinerary',
        name: 'product-itinerary',
        label: '行程设计',
        icon: 'MapLocation',
        meta: {
          title: '行程设计',
          icon: 'MapLocation'
        }
      },
      {
        path: '/product/pricing',
        name: 'product-pricing',
        label: '价格管理',
        icon: 'PriceTag',
        meta: {
          title: '价格管理',
          icon: 'PriceTag'
        }
      },
      {
        path: '/product/inventory',
        name: 'product-inventory',
        label: '库存管理',
        icon: 'Box',
        meta: {
          title: '库存管理',
          icon: 'Box'
        }
      },
      {
        path: '/product/materials',
        name: 'product-materials',
        label: '产品资料',
        icon: 'FolderOpened',
        meta: {
          title: '产品资料',
          icon: 'FolderOpened'
        }
      },
      {
        path: '/product/recommendation',
        name: 'product-recommendation',
        label: '推荐配置',
        icon: 'StarFilled',
        meta: {
          title: '推荐配置',
          icon: 'StarFilled'
        }
      },
      {
        path: '/product/analytics',
        name: 'product-analytics',
        label: '销售分析',
        icon: 'DataLine',
        meta: {
          title: '销售分析',
          icon: 'DataLine'
        }
      },
      {
        path: '/product/preview',
        name: 'product-preview',
        label: '详情预览',
        icon: 'el-icon-view',
        meta: {
          title: '详情预览',
          icon: 'el-icon-view',
          hidden: true
        }
      }
    ]
  },
  {
    path: '/activity',
    name: 'activity',
    label: '邀约活动',
    icon: 'Present',
    meta: {
      title: '邀约活动',
      icon: 'Present'
    },
    children: [
      {
        path: '/activity/types',
        name: 'activity-types',
        label: '活动类型',
        icon: 'Menu',
        meta: {
          title: '活动类型',
          icon: 'Menu'
        }
      },
      {
        path: '/activity/list',
        name: 'activity-list',
        label: '活动列表',
        icon: 'Calendar',
        meta: {
          title: '活动列表',
          icon: 'Calendar',
          keepAlive: true
        }
      },
      {
        path: '/activity/form',
        name: 'activity-form',
        label: '活动创建',
        icon: 'Edit-outline',
        meta: {
          title: '活动创建',
          icon: 'Edit-outline'
        }
      },
      {
        path: '/activity/invitation',
        name: 'activity-invitation',
        label: '客户邀请',
        icon: 'Message',
        meta: {
          title: '客户邀请',
          icon: 'Message'
        }
      },
      {
        path: '/activity/execution',
        name: 'activity-execution',
        label: '活动执行',
        icon: 'VideoPlay',
        meta: {
          title: '活动执行',
          icon: 'VideoPlay'
        }
      },
      {
        path: '/activity/evaluation',
        name: 'activity-evaluation',
        label: '效果评估',
        icon: 'Medal',
        meta: {
          title: '效果评估',
          icon: 'Medal'
        }
      }
    ]
  },
  {
    path: '/tour',
    name: 'tour',
    label: '出团管理',
    icon: 'Guide',
    meta: {
      title: '出团管理',
      icon: 'Guide'
    },
    children: [
      {
        path: '/tour/dashboard',
        name: 'tour-dashboard',
        label: '团队管理',
        icon: 'UserFilled',
        meta: {
          title: '团队管理',
          icon: 'UserFilled',
          keepAlive: true
        }
      },
      {
        path: '/tour/creation',
        name: 'tour-creation',
        label: '团队组建',
        icon: 'UserFilled',
        meta: {
          title: '团队组建',
          icon: 'UserFilled'
        }
      },
      {
        path: '/tour/members',
        name: 'tour-members',
        label: '团员管理',
        icon: 'Check',
        meta: {
          title: '团员管理',
          icon: 'Check'
        }
      },
      {
        path: '/tour/preparation',
        name: 'tour-preparation',
        label: '出团准备',
        icon: 'Suitcase',
        meta: {
          title: '出团准备',
          icon: 'Suitcase'
        }
      },
      {
        path: '/tour/monitoring',
        name: 'tour-monitoring',
        label: '实时监控',
        icon: 'el-icon-view',
        meta: {
          title: '实时监控',
          icon: 'el-icon-view'
        }
      },
      {
        path: '/tour/emergency',
        name: 'tour-emergency',
        label: '应急处理',
        icon: 'Warning',
        meta: {
          title: '应急处理',
          icon: 'Warning'
        }
      },
      {
        path: '/tour/billing',
        name: 'tour-billing',
        label: '费用结算',
        icon: 'Wallet',
        meta: {
          title: '费用结算',
          icon: 'Wallet'
        }
      },
      {
        path: '/tour/summary',
        name: 'tour-summary',
        label: '团队总结',
        icon: 'DocumentCopy',
        meta: {
          title: '团队总结',
          icon: 'DocumentCopy'
        }
      }
    ]
  },
  {
    path: '/aftercare',
    name: 'aftercare',
    label: '售后服务',
    icon: 'CustomerService',
    meta: {
      title: '售后服务',
      icon: 'CustomerService'
    },
    children: [
      {
        path: '/aftercare/dashboard',
        name: 'aftercare-dashboard',
        label: '服务仪表板',
        icon: 'el-icon-data-board',
        meta: {
          title: '服务仪表板',
          icon: 'el-icon-data-board',
          keepAlive: true
        }
      },
      {
        path: '/aftercare/follow-up',
        name: 'aftercare-follow-up',
        label: '回访管理',
        icon: 'Phone',
        meta: {
          title: '回访管理',
          icon: 'Phone'
        }
      },
      {
        path: '/aftercare/satisfaction',
        name: 'aftercare-satisfaction',
        label: '满意度调查',
        icon: 'StarFilled',
        meta: {
          title: '满意度调查',
          icon: 'StarFilled'
        }
      },
      {
        path: '/aftercare/complaints',
        name: 'aftercare-complaints',
        label: '投诉处理',
        icon: 'el-icon-warning',
        meta: {
          title: '投诉处理',
          icon: 'el-icon-warning'
        }
      },
      {
        path: '/aftercare/care',
        name: 'aftercare-care',
        label: '客户关怀',
        icon: 'Present',
        meta: {
          title: '客户关怀',
          icon: 'Present'
        }
      },
      {
        path: '/aftercare/repurchase',
        name: 'aftercare-repurchase',
        label: '复购促进',
        icon: 'RefreshRight',
        meta: {
          title: '复购促进',
          icon: 'RefreshRight'
        }
      }
    ]
  },
  {
    path: '/statistics',
    name: 'statistics',
    label: '数据统计',
    icon: 'el-icon-data-analysis',
    meta: {
      title: '数据统计',
      icon: 'el-icon-data-analysis'
    },
    children: [
      {
        path: '/statistics/overview',
        name: 'statistics-overview',
        label: '总览仪表板',
        icon: 'Odometer',
        meta: {
          title: '总览仪表板',
          icon: 'Odometer',
          keepAlive: true
        }
      },
      {
        path: '/statistics/sales',
        name: 'statistics-sales',
        label: '销售数据',
        icon: 'el-icon-money',
        meta: {
          title: '销售数据',
          icon: 'el-icon-money'
        }
      },
      {
        path: '/statistics/customer',
        name: 'statistics-customer',
        label: '客户数据',
        icon: 'el-icon-user',
        meta: {
          title: '客户数据',
          icon: 'el-icon-user'
        }
      },
      {
        path: '/statistics/product',
        name: 'statistics-product',
        label: '产品数据',
        icon: 'Goods',
        meta: {
          title: '产品数据',
          icon: 'Goods'
        }
      },
      {
        path: '/statistics/activity',
        name: 'statistics-activity',
        label: '活动数据',
        icon: 'Present',
        meta: {
          title: '活动数据',
          icon: 'Present'
        }
      },
      {
        path: '/statistics/financial',
        name: 'statistics-financial',
        label: '财务数据',
        icon: 'Coin',
        meta: {
          title: '财务数据',
          icon: 'Coin'
        }
      },
      {
        path: '/statistics/operation',
        name: 'statistics-operation',
        label: '运营数据',
        icon: 'el-icon-pie-chart',
        meta: {
          title: '运营数据',
          icon: 'el-icon-pie-chart'
        }
      }
    ]
  },
  {
    path: '/system',
    name: 'system',
    label: '系统管理',
    icon: 'el-icon-setting',
    meta: {
      title: '系统管理',
      icon: 'el-icon-setting'
    },
    children: [
      {
        path: '/system/users',
        name: 'system-users',
        label: '用户管理',
        icon: 'UserFilled',
        meta: {
          title: '用户管理',
          icon: 'UserFilled'
        }
      },
      {
        path: '/system/monitoring',
        name: 'system-monitoring',
        label: '系统监控',
        icon: 'Monitor',
        meta: {
          title: '系统监控',
          icon: 'Monitor'
        }
      },
      {
        path: '/system/config',
        name: 'system-config',
        label: '基础配置',
        icon: 'Tools',
        meta: {
          title: '基础配置',
          icon: 'Tools'
        }
      },
      {
        path: '/system/roles',
        name: 'system-roles',
        label: '角色管理',
        icon: 'UserFilled',
        meta: {
          title: '角色管理',
          icon: 'UserFilled'
        }
      },
      {
        path: '/system/logs',
        name: 'system-logs',
        label: '日志管理',
        icon: 'el-icon-document',
        meta: {
          title: '日志管理',
          icon: 'el-icon-document'
        }
      },
      {
        path: '/system/data',
        name: 'system-data',
        label: '数据维护',
        icon: 'Files',
        meta: {
          title: '数据维护',
          icon: 'Files'
        }
      },
      {
        path: '/system/permissions',
        name: 'system-permissions',
        label: '权限管理',
        icon: 'Key',
        meta: {
          title: '权限管理',
          icon: 'Key'
        }
      },
      {
        path: '/system/business',
        name: 'system-business',
        label: '业务配置',
        icon: 'Operation',
        meta: {
          title: '业务配置',
          icon: 'Operation'
        }
      },
      {
        path: '/system/integration',
        name: 'system-integration',
        label: '集成管理',
        icon: 'Connection',
        meta: {
          title: '集成管理',
          icon: 'Connection'
        }
      }
    ]
  }
]

// 扁平化菜单数据，用于路由匹配
export const flatMenuData = []

const flattenMenu = (menu, parentPath = '') => {
  menu.forEach(item => {
    const fullPath = parentPath + item.path
    flatMenuData.push({
      ...item,
      path: fullPath
    })
    
    if (item.children && item.children.length > 0) {
      flattenMenu(item.children, fullPath)
    }
  })
}

flattenMenu(menuData)

// 根据路径获取菜单项
export const getMenuByPath = (path) => {
  return flatMenuData.find(item => item.path === path)
}

// 根据路径获取面包屑
export const getBreadcrumbsByPath = (path) => {
  const breadcrumbs = []
  const pathSegments = path.split('/').filter(Boolean)
  
  let currentPath = ''
  pathSegments.forEach(segment => {
    currentPath += `/${segment}`
    const menuItem = getMenuByPath(currentPath)
    if (menuItem && menuItem.meta && !menuItem.meta.hidden) {
      breadcrumbs.push({
        path: currentPath,
        title: menuItem.meta.title || menuItem.label,
        icon: menuItem.meta.icon || menuItem.icon
      })
    }
  })
  
  return breadcrumbs
}

export default {
  menuData,
  flatMenuData,
  getMenuByPath,
  getBreadcrumbsByPath
}